#!/usr/bin/ruby -Ku
# -*- coding: utf-8-emacs -*-
require 'test/unit'
require 'm3g'

class Test_KeyframeSequence < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_default_variables
    key_seq = M3G::KeyframeSequence.new 10, 3, M3G::KeyframeSequence::LINEAR
    
    assert_equal 10, key_seq.keyframe_count
    assert_equal 3 , key_seq.component_count
    assert_equal M3G::KeyframeSequence::LINEAR  , key_seq.interpolation_type
    assert_equal M3G::KeyframeSequence::CONSTANT, key_seq.repeat_mode
    assert_equal 0 , key_seq.valid_range.first
    assert_equal 9 , key_seq.valid_range.last

    # 初期値は0である事が仕様で定義されている
    for i in 0..9
      time, value = key_seq.keyframe[i]
      assert_equal 0, time
      assert_equal 0, value[0]
      assert_equal 0, value[1]
      assert_equal 0, value[2]
    end
  end
    
  def test_set_variables
    key_seq = M3G::KeyframeSequence.new 10, 3, M3G::KeyframeSequence::LINEAR
    key_seq.duration    = 1000
    key_seq.repeat_mode = M3G::KeyframeSequence::LOOP
    key_seq.valid_range = [5,9]

    for i in 0..9
      key_seq.keyframe[i] = [i, [i+1,i+2,i+3]]
    end
    
    assert_equal 10  , key_seq.keyframe_count
    assert_equal 3   , key_seq.component_count
    assert_equal M3G::KeyframeSequence::LINEAR, key_seq.interpolation_type
    assert_equal M3G::KeyframeSequence::LOOP  , key_seq.repeat_mode
    assert_equal 1000, key_seq.duration
    assert_equal 5   , key_seq.valid_range.first
    assert_equal 9   , key_seq.valid_range.last
    
    for i in 0..9
      time, value = key_seq.keyframe[i]
      assert_equal i  , time
      assert_equal i+1, value[0]
      assert_equal i+2, value[1]
      assert_equal i+3, value[2]
    end
  end

  def test_duplicate
    key_seq1 = M3G::KeyframeSequence.new 10, 3, M3G::KeyframeSequence::LINEAR
    key_seq1.duration    = 1000
    key_seq1.repeat_mode = M3G::KeyframeSequence::LOOP
    key_seq1.valid_range = [0,4]

    for i in 0..9
      key_seq1.keyframe[i] = [i, [i+1,i+2,i+3]]
    end
    
    key_seq2 = key_seq1.duplicate

    assert_equal 10  , key_seq2.keyframe_count
    assert_equal 3   , key_seq2.component_count
    assert_equal M3G::KeyframeSequence::LINEAR, key_seq2.interpolation_type
    assert_equal M3G::KeyframeSequence::LOOP  , key_seq2.repeat_mode
    assert_equal 1000, key_seq2.duration
    assert_equal 0   , key_seq2.valid_range.first
    assert_equal 4   , key_seq2.valid_range.last
    
    for i in 0..9
      time, value = key_seq2.keyframe[i]
      assert_equal i  , time
      assert_equal i+1, value[0]
      assert_equal i+2, value[1]
      assert_equal i+3, value[2]
    end

  end

end
